package com.hzm.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzm.dao.CourseDao;
import com.hzm.service.CourseService;
import com.hzm.utils.Result;
import com.hzm.vo.CourseDetailsVo;
import com.hzm.vo.KeShiVo;
import com.qy137.entity.Course;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @program: qy137-java
 * @description:
 * @author: 皇子明
 * @create:
 **/
@Service
public class CourseServiceImpl extends ServiceImpl<CourseDao , Course> implements CourseService {
    @Resource
    private CourseDao courseDao;
    @Override
    public Result querAllCourse(String courseId) {
        List<Course> courseList= courseDao.queryCourseById(courseId);
        Result result = new Result(2000, "成功", courseList);
        return result;
    }

    @Override
    public Result queryAllCourseAndTeacherName(String id) {
        CourseDetailsVo courseDetailsVo = courseDao.queryAllCourseAndTeacherName(id);

        Long VierCount= courseDetailsVo.getViewCount()+1;
        Course course = new Course();
        course.setId(id);
        course.setViewCount(VierCount);
        courseDao.updateById(course);
        Result result = new Result(2000, "成功", courseDetailsVo);
        return result;
    }

    @Override
    public Result queryAllKeShi(String id) {
        KeShiVo keShiVo= courseDao.queryAllKeShi(id);
        Result result = new Result(2000, "成功", keShiVo);
        return result;
    }

    @Override
    public Result querAllBy(String id, String mobile) {
        List<Course> courses =courseDao.queryAllById(id,mobile);
        if (courses.size()>0){
            Result result = new Result(2000, "查询成功", courses);
            return result;
        }
        Result result = new Result(5000, "查询成功", null);
        return result;
    }

    @Override
    public Result queryMemberStatus(String id, String mobile) {
        Course course = courseDao.queryMemberStatus(id,mobile);
        if (course!=null){
            Result result = new Result(2000, "查询成功", course);
            return result;
        }
        Result result = new Result(5000, "查询成功", null);
        return result;
    }
}










